package com.jp.knowledge.my.activity;

import android.content.Intent;

import com.google.gson.JsonObject;
import com.jiayen.util.ToasUtil;
import com.jp.knowledge.http.HttpHelper;
import com.jp.knowledge.model.IModel;
import com.jp.knowledge.my.model.IndustryModel;
import com.jp.knowledge.util.ResultSubscriber;

import java.util.ArrayList;
import java.util.List;

public class OptionCompanyOccupationActivity extends OptionActivity implements ResultSubscriber.OnResultListener {

    public static final String INDUSTRY_ID = "industryId";

    private List<IndustryModel> industryList;

    @Override
    protected void init() {
        super.init();

        industryList = new ArrayList<>();
        loading.show();
        JsonObject param = new JsonObject();
        param.addProperty("token", HttpHelper.token);
        HttpHelper.getInstance(this).getIndustryList(param, 0x01, this);
    }

    @Override
    public Intent putMessageToIntent(Intent intent, int position) {
        intent.putExtra(INDUSTRY_ID, industryList.get(position).getId());
        return intent;
    }

    @Override
    public void onStart(int requestType) {}
    @Override
    public void onCompleted(int requestType) {
        loading.cancel();
    }
    @Override
    public void onError(int requestType) {
        loading.cancel();
        ToasUtil.toast(this, "抱歉，行业信息获取失败，请稍后重试");
    }
    @Override
    public void onNext(IModel data, int requestType) {
        if(requestType != 0x01)
            return;
        industryList = data.getList(IndustryModel.class);
        List<String> industryNames = new ArrayList<>();
        for(IndustryModel industryModel : industryList){
            industryNames.add(industryModel.getName());
        }
        adapter.updateAdapter(industryNames);
    }
}
